﻿#include"main.hpp"

void printtmenu();
void testadd();
void testedit();
void testdel();
void in()
{
	FILE* testci, * testvi;
	if ((testci = fopen("tesl.txt", "rb")) == NULL)
	{
		FILE* pul = fopen("tesl.txt", "wb");
		fprintf(pul, "%d", tesl);
		fclose(pul);
		testci = fopen("tesl.txt", "rb");
	}
	if ((testvi = fopen("tests.txt", "rb")) == NULL)
	{
		FILE* pul = fopen("tests.txt", "wb");
		fwrite(tt, sizeof(test), 10, pul);
		fclose(pul);
		testvi = fopen("tests.txt", "rb");
	}
	fscanf(testci, "%d", &tesl);
	fread(tt, sizeof(test), 10, testvi);
	fclose(testci); fclose(testvi);
}
void testn()
{
	bool circ = true;
	in();
	while (circ)
	{
		printtmenu();
		int sel; scanf("%d", &sel);
		switch (sel)
		{
		case 1:testcoi(); break;
		case 2:testadd(); break;
			//case 3:testedit();break;
			//case 4:testdel();break;
		case 5:circ = false; break;
		default:printf("格式错误！\n"); break;
		}
		system("pause");
		system("cls");
	}
}
void printtmenu()
{
	printf("欢迎来到考试管理菜单！\n");
	printf("1.选择考试\n");
	printf("2.添加考试\n");
	printf("3.修改考试\n");
	printf("4.删除考试\n");
	printf("5.退出考试管理\n");
}
void testcoi()
{
	in();
	int sn = 0; bool circ;
	printf("请选择考试：\n");
	for (int i = 1;; i++)
	{
		if (tt[i].state == 1)
		{
			printf("%d.%s\n", i, tt[i].name);
			sn++;
		}
		if (i == 10 && sn == 0)
		{
			printf("未检测到考试，请添加考试！\n");
			system("pause");
			testadd();
			printf("请选择考试：\n");
			i = 0;
		}
		else if (i > 10) break;
	}
	scanf("%d", &tesl);
	printf("选择成功！\n");
	system("pause");
	system("cls");
}
void testadd()
{
	tt[++tnum].state = 1;
	printf("请输入考试名称：\n");
	scanf("%s", tt[tnum].name);
	printf("请输入考试日期（年-月-日）：\n");
	for (int i = 0; i < 3; i++) scanf("%d", &tt[tnum].date[i]);
	printf("添加成功！\n");
	system("pause");
	system("cls");
}
